package com.kemai.designmode.ui
import android.os.Bundle
import com.kemai.common.adapter.ItemClickListener
import com.kemai.common.ui.BaseActivity
import com.kemai.designmode.R
import com.kemai.designmode.entry.Fruit
import com.kemai.designmode.factory.method.AppleMethodFactory
import com.kemai.designmode.factory.method.BananaMethodFactory
import com.kemai.designmode.factory.method.OrangeMethodFactory
//工厂方法模式调用（每一种对象就是一个工厂,避免穿参错误）
class FactoryMethodActivity : BaseActivity(), ItemClickListener {
    private val studyContent = arrayOf("获取苹果","获取香蕉","获取桔子")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_common_content)
        findViewById()
        setTiTle("工厂方法模式")
        setAdapterContent(studyContent,FactoryMethodActivity@this,FactoryMethodActivity@this)

    }
    override fun itemClick(position: Int) {
        var fruit:Fruit? = null
        when(position){
            0->{
                fruit = AppleMethodFactory().getFruit()

            }
            1->{
                fruit = BananaMethodFactory().getFruit()

            }
            2->{
                fruit = OrangeMethodFactory().getFruit()

            }

        }
        fruit?.draw()

    }

}